package com.changhong.framework.sdfs.namenode.server.directory;

import com.alibaba.fastjson.JSONObject;
import com.changhong.framework.sdfs.namenode.server.builder.NameNodeBuilder;
import com.changhong.framework.sdfs.namenode.server.constant.OperationType;
import com.changhong.framework.sdfs.namenode.server.nio.FileOperationManager;

/**
 * 文件管理组件
 * @author Summer
 */
public class DefaultFileManagerSystem implements  FileManagerSystem{
    private final DirectoryManager directoryManager;
    private final FileOperationManager fileOperationManager;

    public DefaultFileManagerSystem(){
        this.directoryManager= NameNodeBuilder.getInstance(DirectoryManager.class);
        this.fileOperationManager=NameNodeBuilder.getInstance(FileOperationManager.class);
    }

    @Override
    public boolean createDir(String path) throws Exception {
        boolean result = directoryManager.createDir(path);
        if(result){
            fileOperationManager.operation(JSONObject.toJSONString(OperationLogFactory.creatOperation(path, OperationType.NEW)));
            return true;
        }
        return false;
    }
}
